package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.PopulationFixedDetailBean;
import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.IPopFixedAddView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *留守人员新增/修改
 */
public class PopFixedAddPest {

    private IPopFixedAddView addView;

    public PopFixedAddPest(IPopFixedAddView addView) {
        this.addView=addView;
    }


    /**
     * @param orgId 组织id
     * @param id 留守人员id
     * @param url 修改的图片地址
     * @param detailBean 境外人员详情
     */
    public void addFixed(String path, String orgId,String id,String url, PopulationFixedDetailBean detailBean){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("orgId", orgId);
        map.put("leftBehindPeople.id", id);
        if (detailBean!=null){
            map.put("leftBehindPeople.idCardNo",detailBean.getIdCardNo());
            if (!BaseUtil.isEmpty(detailBean.getActualPopulationType())){
                map.put("leftBehindPeople.actualPopulationType",detailBean.getActualPopulationType());
            }
            map.put("leftBehindPeople.name",detailBean.getName());
            map.put("leftBehindPeople.gender.id",detailBean.getGender().getId());
            map.put("leftBehindPeople.birthday",detailBean.getBirthday());
            map.put("leftBehindPeople.nation.id",detailBean.getNation().getId());
            map.put("leftBehindPeople.politicalBackground.id",detailBean.getPoliticalBackground().getId());
            map.put("leftBehindPeople.maritalState.id",detailBean.getMaritalState().getId());
            map.put("leftBehindPeople.province",detailBean.getProvince());
            map.put("leftBehindPeople.city",detailBean.getCity());
            map.put("leftBehindPeople.district",detailBean.getDistrict());
            map.put("leftBehindPeople.placeProvince",detailBean.getPlaceProvince());
            map.put("leftBehindPeople.placeCity",detailBean.getPlaceCity());
            map.put("leftBehindPeople.placeDistrict",detailBean.getPlaceDistrict());
            map.put("leftBehindPeople.presentProvince",detailBean.getPresentProvince());
            map.put("leftBehindPeople.presentCity",detailBean.getPresentCity());
            map.put("leftBehindPeople.presentDistrict",detailBean.getPresentDistrict());
            map.put("leftBehindPeople.nativePlaceAddress",detailBean.getNativePlaceAddress());
            map.put("leftBehindPeople.isHaveHouse",detailBean.isIsHaveHouse());
            if (detailBean.isIsHaveHouse()){
                map.put("leftBehindPeople.currentAddress",detailBean.getCurrentAddress());
            }else {
                map.put("leftBehindPeople.noHouseReason",detailBean.getNoHouseReason());
            }
            map.put("leftBehindPeople.telephone",detailBean.getTelephone());
            map.put("leftBehindPeople.mobileNumber",detailBean.getMobileNumber());
            map.put("leftBehindPeople.schoolStr",detailBean.getSchoolVal());
            map.put("leftBehindPeople.career.id",detailBean.getCareer().getId());
            map.put("leftBehindPeople.careerText",detailBean.getCareerText());
            map.put("leftBehindPeople.usedName",detailBean.getUsedName());
            map.put("leftBehindPeople.faith.id",detailBean.getFaith()!=null?
                        detailBean.getFaith().getId():"");
            map.put("leftBehindPeople.workUnit",detailBean.getWorkUnit());
            map.put("leftBehindPeople.health.id",detailBean.getHealth()!=null?
                    detailBean.getHealth().getId():"");
            map.put("leftBehindPeople.residenceType.id",detailBean.getResidenceType()!=null?
                    detailBean.getResidenceType().getId():"");
            map.put("leftBehindPeople.personalAnnualIncome",detailBean.getPersonalAnnualIncome());
            map.put("leftBehindPeople.leftType.id",detailBean.getLeftType().getId());
            map.put("leftBehindPeople.householdIdentity.id",detailBean.getHouseholdIdentity().getId());
            map.put("leftBehindPeople.familyMainIdCard",detailBean.getFamilyMainIdCard());
            map.put("leftBehindPeople.familyMainName",detailBean.getFamilyMainName());
            map.put("leftBehindPeople.familyMainHealth.id",detailBean.getFamilyMainHealth()!=null?
                    detailBean.getFamilyMainHealth().getId():"");
            map.put("leftBehindPeople.leftRelationship.id",detailBean.getLeftRelationship().getId());
            map.put("leftBehindPeople.familyMainPhone",detailBean.getFamilyMainPhone());
            map.put("leftBehindPeople.familyTelephone",detailBean.getFamilyTelephone());
            map.put("leftBehindPeople.familyAnnualIncome",detailBean.getFamilyAnnualIncome());
            map.put("leftBehindPeople.familyMainAdress",detailBean.getFamilyMainAdress());
            map.put("leftBehindPeople.difficultiesAndDemands",detailBean.getDifficultiesAndDemands());
            map.put("leftBehindPeople.helpingSituation",detailBean.getHelpingSituation());
            if (!BaseUtil.isEmpty(url)&&!url.startsWith("http")){
                map.put("file.path",url);
            }
        }

        new CollectManager().addFixed(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                addView.addSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                addView.showError(message);
            }
        });
    }

}
